<template>
  <div>
    <v-tableTitle
      :btnConfig="btnConfig1"
      :tableSelectData="selectData"
      @del="del"
    ></v-tableTitle>
    <div class="detail">
      <v-navMenu
        :detailNav="detailNav"
        :menuData="menuData"
        @setMentActive="setMentActive"
      ></v-navMenu>
      <component
        :inputData="detailData"
        :is="currentComponent"
        ref="comRef"
      ></component>
    </div>
  </div>

</template>

<script>
import navMenu from "@/components/commons/NavMenu";
import tableTitle from "@/components/commons/TableTitle";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
  name: "Detail",
  mixins: [baseMixin, config],
  data () {
    return {
      flag: true,
      newFlag: false,
      selectData: [],
      detailData: {},
      detailNav: "1",
      componentConfig: [
        {
          name: "kwscDetailListPage",
          label: this.$t('work.delKw'),
          component: () => import('./page/kwscDetailListPage.vue')
        },
        {
          name: "kwsdDetailListPage",
          label: this.$t('work.editKw'),
          component: () => import('./page/kwsdDetailListPage.vue')
        },
      ],
    }
  },
  computed: {
    btnConfig1 () {
      if (this.detailNav == 1) {
        return [
          { label: this.$t('common.delete'), certigier: this.deleteDetailStatus||!this.btnPermNameList.includes('WM031308'), disabled: true, invalid: "del" },
        ]
      }
      return []
    },
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    },

  },
  methods: {
    initData (dataId) {
      this.$refs.comRef.initTable(dataId)
    },
    setMentActive (key) {
      this.detailNav = key;
    },
    getData (dataId) {
      if (this.detailNav == 1) {
        this.detailData.showKw = this.detailNav
        this.$refs.comRef.getTableData(this.detailNav, dataId)
      } else {
        this.$api.post(`/PartsLibraryScreen/showKw/${this.detailNav}/${dataId}`).then(res => {
          
            this.initIfame(dataId)
          
        })


      }

    },
    async initIfame (dataId) {
      let whseid = this.$store.state.wms;
      let users = this.$Cookies.get('user');
      let name = 'LJWPLSECODE';
      try {
        let response = await this.$api.get(`/getHttpUrl/${name}`);
          let url = `${response.bean}?whseid=${whseid}&users=${users}&screenId=` + dataId;
          // let url = `http://localhost:8085/rtxext/PbInitLoadScreenServlet?whseid=${whseid}&users=${users}&screenId=` + dataId;
          this.$refs.comRef.src = url
      } catch (e) {
        this.$message.error(e);
      }
    },
    //选中的数据
    setSelectData (data) {
      this.selectData = data;
    },
    del () {
      this.$api.post(`/PartsLibraryScreen/deleteKwByList/${this.detailNav}`, this.selectData).then(res => {
        
          this.$message.success(res.returnMgr);
        
      })
    },
  },
  mounted () {
    if (this.$store.state.temporary) {
      this.detailNav = this.$store.state.temporary
    }

  },
  components: {
    "v-navMenu": navMenu,
    "v-tableTitle": tableTitle,
  },
  watch: {
    selectData (data) {
      if (data.length > 0) {
        this.deleteDetailStatus = false;
      } else {
        this.deleteDetailStatus = true;
      }
    },
  }

}
</script>

<style scoped>
</style>
